package com.zyit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.zyit.mapper.OrderInfoMapper;
import com.zyit.mapper.PaymentInfoMapper;
import com.zyit.pojo.OrderInfo;
import com.zyit.pojo.PaymentInfo;
import com.zyit.service.OrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private PaymentInfoMapper paymentInfoMapper;
    @Override
    public OrderInfo findById(Long id) {
        return orderInfoMapper.selectById(id);
    }

    @Override
    public int addOrder(OrderInfo info) {
        return orderInfoMapper.insert(info);
    }

    @Override
    public int changeOrderStatus(PaymentInfo paymentInfo) {
        //添加支付记录
        paymentInfoMapper.insert(paymentInfo);
        //更新订单状态
        UpdateWrapper wrapper = new UpdateWrapper();
        wrapper.set("order_status",2L);
        wrapper.set("pay_time",paymentInfo.getCallbackTime());
        wrapper.eq("id",paymentInfo.getOrderId());
        return orderInfoMapper.update(wrapper);
    }
}
